package com.openbravo.pos.config;

import com.openbravo.data.user.DirtyManager;
import com.openbravo.pos.forms.AppConfig;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.payment.ConfigPaymentPanelCaixa;
import com.openbravo.pos.payment.ConfigPaymentPanelEmpty;
import com.openbravo.pos.payment.ConfigPaymentPanelGeneric;
import com.openbravo.pos.payment.ConfigPaymentPanelLinkPoint;
import com.openbravo.pos.payment.PaymentConfiguration;

import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.GroupLayout.SequentialGroup;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.LayoutStyle;
import javax.swing.LayoutStyle.ComponentPlacement;

public class JPanelConfigPayment extends JPanel
  implements PanelConfig
{
  private DirtyManager dirty = new DirtyManager();
  private Map<String, PaymentConfiguration> paymentsName = new HashMap();
  private PaymentConfiguration pc;
  private JLabel jLabel11;
  private JLabel jLabel13;
  private JPanel jPanel1;
  private JPanel jPanel2;
  private JComboBox jcboCardReader;
  private JComboBox jcboPaymentGateway;
  private JCheckBox jchkPaymentTest;

  public JPanelConfigPayment()
  {
    initComponents();
    this.jcboCardReader.addActionListener(this.dirty);
    this.jcboPaymentGateway.addActionListener(this.dirty);
    this.jchkPaymentTest.addActionListener(this.dirty);
    initPayments("Not defined", new ConfigPaymentPanelEmpty());
    initPayments("external", new ConfigPaymentPanelEmpty());
    initPayments("PayPoint / SecPay", new ConfigPaymentPanelGeneric());
    initPayments("AuthorizeNet", new ConfigPaymentPanelGeneric());
    initPayments("Planetauthorize", new ConfigPaymentPanelGeneric());
    initPayments("Firs Data / LinkPoint / YourPay", new ConfigPaymentPanelLinkPoint());
    initPayments("PaymentsGateway.net", new ConfigPaymentPanelGeneric());
    initPayments("La Caixa (Spain)", new ConfigPaymentPanelCaixa());
    this.jcboCardReader.addItem("Not defined");
    this.jcboCardReader.addItem("Generic");
    this.jcboCardReader.addItem("Alternative");
    this.jcboCardReader.addItem("Intelligent");
    this.jcboCardReader.addItem("Keyboard");
  }

  public boolean hasChanged()
  {
    return this.dirty.isDirty();
  }

  public Component getConfigComponent()
  {
    return this;
  }

  public void loadProperties(AppConfig paramAppConfig)
  {
    this.jcboCardReader.setSelectedItem(paramAppConfig.getProperty("payment.magcardreader"));
    this.jcboPaymentGateway.setSelectedItem(paramAppConfig.getProperty("payment.gateway"));
    this.jchkPaymentTest.setSelected(Boolean.valueOf(paramAppConfig.getProperty("payment.testmode")).booleanValue());
    this.pc.loadProperties(paramAppConfig);
    this.dirty.setDirty(false);
  }

  public void saveProperties(AppConfig paramAppConfig)
  {
    paramAppConfig.setProperty("payment.magcardreader", comboValue(this.jcboCardReader.getSelectedItem()));
    paramAppConfig.setProperty("payment.gateway", comboValue(this.jcboPaymentGateway.getSelectedItem()));
    paramAppConfig.setProperty("payment.testmode", Boolean.toString(this.jchkPaymentTest.isSelected()));
    this.pc.saveProperties(paramAppConfig);
    this.dirty.setDirty(false);
  }

  private void initPayments(String paramString, PaymentConfiguration paramPaymentConfiguration)
  {
    this.jcboPaymentGateway.addItem(paramString);
    this.paymentsName.put(paramString, paramPaymentConfiguration);
  }

  private String comboValue(Object paramObject)
  {
    return paramObject == null ? "" : paramObject.toString();
  }

  private void initComponents()
  {
    this.jPanel1 = new JPanel();
    this.jLabel13 = new JLabel();
    this.jLabel11 = new JLabel();
    this.jcboCardReader = new JComboBox();
    this.jcboPaymentGateway = new JComboBox();
    this.jchkPaymentTest = new JCheckBox();
    this.jPanel2 = new JPanel();
    this.jPanel1.setBorder(BorderFactory.createTitledBorder(AppLocal.getIntString("Label.Payment")));
    this.jLabel13.setText(AppLocal.getIntString("label.paymentgateway"));
    this.jLabel11.setText(AppLocal.getIntString("label.magcardreader"));
    this.jcboPaymentGateway.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JPanelConfigPayment.this.jcboPaymentGatewayActionPerformed(paramActionEvent);
      }
    });
    this.jchkPaymentTest.setText(AppLocal.getIntString("label.paymenttestmode"));
    this.jPanel2.setLayout(new GridLayout(1, 1));
    GroupLayout localGroupLayout1 = new GroupLayout(this.jPanel1);
    this.jPanel1.setLayout(localGroupLayout1);
    localGroupLayout1.setHorizontalGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout1.createSequentialGroup().addContainerGap().addComponent(this.jLabel13, -2, 130, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jcboPaymentGateway, -2, 240, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jchkPaymentTest, -2, 130, -2).addContainerGap(155, 32767)).addGroup(localGroupLayout1.createSequentialGroup().addContainerGap().addComponent(this.jLabel11, -2, 130, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jcboCardReader, -2, 240, -2).addContainerGap(287, 32767)).addComponent(this.jPanel2, -1, 681, 32767));
    localGroupLayout1.setVerticalGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, localGroupLayout1.createSequentialGroup().addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabel11).addComponent(this.jcboCardReader, -2, 20, -2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, -1, 32767).addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabel13).addComponent(this.jcboPaymentGateway, -2, 20, -2).addComponent(this.jchkPaymentTest, -2, 20, -2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jPanel2, -2, 104, -2).addContainerGap()));
    GroupLayout localGroupLayout2 = new GroupLayout(this);
    setLayout(localGroupLayout2);
    localGroupLayout2.setHorizontalGroup(localGroupLayout2.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout2.createSequentialGroup().addContainerGap().addComponent(this.jPanel1, -1, -1, 32767).addContainerGap()));
    localGroupLayout2.setVerticalGroup(localGroupLayout2.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout2.createSequentialGroup().addContainerGap().addComponent(this.jPanel1, -2, 183, -2).addContainerGap(-1, 32767)));
  }

  private void jcboPaymentGatewayActionPerformed(ActionEvent paramActionEvent)
  {
    this.pc = ((PaymentConfiguration)this.paymentsName.get(comboValue(this.jcboPaymentGateway.getSelectedItem())));
    if (this.pc != null)
    {
      this.jPanel2.removeAll();
      this.jPanel2.add(this.pc.getComponent());
      this.jPanel2.revalidate();
      this.jPanel2.repaint();
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.config.JPanelConfigPayment
 * JD-Core Version:    0.6.0
 */